package com.msblearn.C_010;

import java.lang.ref.WeakReference;
import java.util.TooManyListenersException;

/**
 * 弱引用
 */
public class T002_WeakReference {
    public static void main(String[] args) {
        WeakReference<M> m = new WeakReference<>(new M());

        System.out.println(m.get());
        System.gc();
        System.out.println(m.get());


        ThreadLocal<M> tl = new ThreadLocal<>();
        tl.set(new M());
        tl.remove(); //使用ThreadLocal要remove掉。免得出现内存泄漏。
    }
}
